package com.my;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;


public class TebakAngka extends MIDlet implements CommandListener{
	private final static int PAUSED = 0;
	private final static int ACTIVE = 1;
	private final static int DESTROYED = 2;
	private static int stateTracker = PAUSED;
	
	Command exitCommand = new Command("Exit", Command.EXIT, 2);
	
	private Display gameDisplay;
	private Looping gameloop;

	public void startApp(){
		if (gameloop == null)
		{
			gameloop = new Looping(this);
			gameloop.startGame();
			
			//add some command
			gameloop.addCommand(exitCommand);
			gameloop.setCommandListener(this);
		}
		gameDisplay.getDisplay(this).setCurrent(gameloop);
		stateTracker = ACTIVE;
	}

	public void pauseApp()
	{
		stateTracker = PAUSED;
		notifyPaused();
	}

	private synchronized void performDestroyCleanup() {
    	if (stateTracker != DESTROYED) {
        	stateTracker = DESTROYED;
            notifyDestroyed();
        }
	}
	
	public void destroyApp(boolean b) throws MIDletStateChangeException {
		performDestroyCleanup();
	}

	public void commandAction(Command c, Displayable s) {
		if(c.getCommandType() == Command.EXIT){
			try {
				destroyApp(true);
			} catch (MIDletStateChangeException e) {
				e.printStackTrace();
			}
		}
	}
}